package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Healthy;
import com._51cto.healthy.service.HealthyService;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/healthy")
public class HealthyController {
    @DubboReference
    private HealthyService healthyService;
    @GetMapping("/page/{pageSize}/{pageNum}")
    public R findPage(@RequestParam(value = "query",required = false)String query,
                      @PathVariable(value = "pageSize")Integer pageSize,
                      @PathVariable(value = "pageNum")Integer pageNum){
        P<Healthy> all = healthyService.findAll(query, pageSize, pageNum);
        return R.success(all);

    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id")Integer id){
        healthyService.deleteByPK(id);
        return R.success("删除成功");
    }
    @PostMapping
    public R insert(@RequestBody Healthy healthy){
        healthyService.insert(healthy);
        return R.success("添加成功");

    }

    @PutMapping
    public R update(@RequestBody Healthy healthy){
        healthyService.update(healthy);
        return R.success("修改成功");
    }
}
